class LinkNode:
    def __init__(self,value,next=None):
        self.value=value
        self.next=next


class MyLinklist:
    def __init__(self):
        self.head = None

    def prepend(self,value):
        """
        表头插入
        :return:
        """
        #实例化一个节点
        new_node=LinkNode(value)
        #把当前节点的下一个节点指向为头节点
        new_node.next=self.head
        #把新节点变成头节点
        self.head=new_node

    def append(self,value):
        """
        尾部插入
        :return:
        """
        # 如果链表为空，让head指向新节点
        if not self.head:
            self.head=LinkNode(value)
        else:
            # 不为空，定义指针到链表头
            current=self.head
            # 移动到链表尾
            while current.next:
                current=current.next
            # 将新节点连接到最后一个节点后
            current.next=LinkNode(value)
    def insert(self,value,index):
        """
        指定位置插入
        :return:
        """
        if not self.head:
            self.prepend(value)
        else:
            current = self.head
            for i in range(index-1):
                    current=current.next
            new_node=LinkNode(value)
            new_node.next=current.next
            current.next=new_node



    def display(self):
        """
        打印链表
        :return:
        """
        values=[]
        if not self.head:
            pass
        current = self.head
        while current:
            values.append(str(current.value))
            current = current.next
        print(" -> ".join(values))
    def find(self,value):
        """
        查询内容在链表位置
        :return:
        """
        current=self.head
        while current:
            if current.value==value:
                return current
            current=current.next
        return None
    def delete(self,value):
        """
        删除
        :return:
        """
        if not self.head:
            return
        else:
            if self.head.value==value:
                #头节点删除
                self.head=self.head.next
            else:
                fast = self.head
                slow = None
                while fast:
                    if fast.value==value:
                        slow.next=fast.next
                        fast.next=None
                        break
                    slow=fast
                    fast=fast.next
                del fast

